#include<iostream>
#include<string.h>
#include<vector>
using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::string;

class Computer
{
public:
    static Computer* init(const char*msg=nullptr,int price=0)
    {
        if(p==nullptr)
        {
        p=new Computer(msg,price);
        }
        return p;
    }
    static void destroy()
    {
        if(p!=nullptr)
        {
            delete p;
            p=nullptr;
        }
        cout<<"销毁"<<endl;
    }
    void print()
    {
        cout<<"("<<_brand<<","
            <<_price<<")"<<endl;
    }
private:
    //声明成员函数，将析构、构造隐藏、将拷贝、赋值删除
    Computer(const char* msg,int& price)
        //预先申请一个字节的空间
        :_brand(new char[1]())
         ,_price(price)
    {
        if(_brand!=nullptr)
        {
            delete []_brand;
        }
        _brand=new char[strlen(msg)+1]();
        strcpy(_brand,msg);
        cout<<"构造函数"<<endl;
        
    }
    Computer(const Computer& rhs)=delete;
    Computer& operator=(const Computer& rhs)=delete;
    ~Computer()
    {
        if(_brand!=nullptr)
        {
            delete []_brand;
            _brand=nullptr;
        }
        cout<<"析构"<<endl;

    }
    //声明成员对象
    char *_brand;
    int _price;
    static Computer* p;
};

Computer* Computer::p=nullptr;

int main()
{
    Computer::init("huawei",8000)->print();
    Computer::init("lenovo",8000)->print();
    Computer::init("xiaomi",8000)->print();
    Computer::destroy();
    Computer::destroy();
    Computer::init("yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy",8000)->print();
    Computer *p =Computer::init("xiaomi",8080);
    cout<<p<<endl;
    cout<<Computer::init()<<endl;
    Computer::destroy();
}
